<template>
  <div>
    <!--  已登录-->
    <div class="imgMy imgMy2" v-if="coken">
      <img class="img22" src="./img/avatar.png" alt="" />
      <div class="position">
        <div class="Myvv">
          <img src="./img/登录成功.jpg" alt="" />

          <div>
            <p class="p2">狗蛋一号</p>
            <a @click="tuichu" class="tuichu">退出</a>
            <p class="p1">编辑资料 &nbsp; &nbsp;></p>
          </div>
        </div>
      </div>
    </div>
    <!-- 未登录 -->
    <div class="imgMy" v-else>
      <img src="./img/bg.png" />
      <div class="position">
        <div class="Myvv">
          <img src="./img/VVWLLO6M6@~IJCAV[W~R{8V.jpg" alt="" />
          <div>
            <p>游客</p>
            <a @click="login"><span>去登录</span></a>
          </div>
        </div>
      </div>
    </div>
    <van-grid :column-num="3" :border="false">
      <van-grid-item class="nevbar">
        <div class="layou">
          <span class="zufang zufang-shoucang1"></span>
          <span class="span">我的收藏</span>
        </div>
      </van-grid-item>
      <van-grid-item class="nevbar">
        <div class="layou">
          <span class="zufang zufang-fangzi"></span>
          <span class="span">我要出租</span>
        </div>
      </van-grid-item>
      <van-grid-item class="nevbar">
        <div class="layou">
          <span class="zufang zufang-bofangjilu"></span>
          <span class="span">看房记录</span>
        </div>
      </van-grid-item>
      <van-grid-item class="nevbar">
        <div class="layou">
          <span class="zufang zufang-qiapian"></span>
          <span class="span">成为房主</span>
        </div>
      </van-grid-item>
      <van-grid-item class="nevbar">
        <div class="layou">
          <span class="zufang zufang-31wode"></span>
          <span class="span">个人资料</span>
        </div>
      </van-grid-item>
      <van-grid-item class="nevbar">
        <div class="layou">
          <span class="zufang zufang-kefu"></span>
          <span class="span">联系我们</span>
        </div>
      </van-grid-item>
    </van-grid>
    <div class="img2">
      <img src="./img/download.png" alt="" />
    </div>
  </div>
</template>

<script>
import { longout, uesrinfo } from '@/api'
export default {
  created() {
    this.uesrinfoAp()
  },
  methods: {
    login() {
      this.$router.push({
        name: 'login'
      })
    },
    uesrinfoAp() {
      uesrinfo()
    },
    tuichu() {
      //确定是否退出
      this.$dialog
        .confirm({
          title: '提示',
          message: '确定要退出么'
        })
        .then(() => {
          //确认退出
          // longout()
          longout()
          this.$store.commit('DENGLUCOKEN', '')
          this.$toast.success('退出成功')
          // this.$router.push({ path: "/login" });
        })
        .catch(() => {
          //取消退去
        })
    }
  },
  computed: {
    //页面加载判断用户有没有登录
    coken() {
      const coken = this.$store.state.coken
      if (coken) {
        return 'ok'
      } else {
        return 0
      }
    }
  }
}
</script>

<style scoped lang="less">
* {
  margin: 0;
  padding: 0;
}
.imgMy {
  height: 600px;
  position: relative;
  img {
    width: 100%;
  }
  .img22 {
    margin-bottom: 150px;
  }
  .position {
    position: absolute;
    background: #fff;
    width: 85%;
    height: 50%;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 10px 3px #ddd;
    margin: 50px auto 0;
    padding: 0 20px;
    text-align: center;
    font-size: 13px;
    .Myvv {
      position: relative;
      transform: translateY(-50%);
      border-radius: 50%;
      width: 140px;
      height: 140px;
      border: 10px solid #f5f5f5;
      display: inline-block;
      box-shadow: 0 2px 2px #bdbdbd;

      img {
        width: 100%;
        border-radius: 50%;
        margin-bottom: 50px;
      }
      p {
        margin-bottom: 35px;
      }
      a {
        display: inline-block;
        background-color: #21b97a;
        border-radius: 5px;
        width: 160px;
        height: 60px;
        line-height: 60px;
        span {
          color: #fff;
        }
      }
      .p1 {
        font-size: 10px;
        margin-top: 10px;
      }
      .p2 {
        margin-bottom: 10px;
      }
      .tuichu {
        width: 100px;
        height: 50px;
        line-height: 50px;
      }
    }
  }
}
.imgMy2 {
  height: 800px;
}
.nevbar {
  .layou {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    height: 100px;
    margin-top: 10px;
    .zufang {
      font-size: 42px;
    }
    .span {
      font-size: 13px;
    }
  }
}
.img2 {
  width: 700px;
  margin: 70px auto;
  img {
    width: 100%;
  }
}
</style>
